#include "ticketquery.h"

template<typename K, typename T>
void toggleValueInList(const K &field, bool value, T &list)
{
    if (value && !list.contains(field))
        list << field;
    else if (!value)
        list.removeOne(field);
}

TicketQuery::TicketQuery(const QString &searchStr, SearchType searchType)
    : m_type(searchType), m_searchStr(searchStr), m_label(QString("All Tickets"))
{
}

void TicketQuery::includeStatus(const QString &status, bool value)
{
    toggleValueInList(status, value, m_statuses);
}

void TicketQuery::addLookupField(const QString &field, TicketQuery::Operator op, const QString &value)
{
    if (!value.trimmed().isEmpty())
        m_fields.insert(field, qMakePair(op, value));
}

void TicketQuery::setLabel(const QString &label)
{
    if (label.isNull() || label.isEmpty())
    {
        m_label = "Custom Query";
    }
    else
    {
        m_label = label;
    }
}


